package com.tea.tl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tea.common.dto.TeaAddDto;
import com.tea.common.vo.R;
import com.tea.tl.dao.TeaDao;
import com.tea.tl.domain.Tea;
import com.tea.tl.service.intf.TeaService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class TeaServiceImpl implements TeaService {
    @Resource
    private TeaDao dao;
    /**
     * 1.增加茶叶*/
    @Override
    public R add(TeaAddDto dto) {
        //1.非null
        if (dto!=null){
            //2.准备对象
            Tea tea = new Tea();
            BeanUtils.copyProperties(dto,tea);
            tea.innit();
            if (dao.insert(tea)>0){
                return R.ok();
            }
        }
        return R.fail();
    }
    /**
     * 2.查看指定茶园茶叶*/
    @Override
    public R select(int tgid) {
        if (tgid>0){
            return R.ok(dao.selectList(new QueryWrapper<Tea>()
                    .eq("tgid",tgid)));
        }
        return R.fail();
    }
}
